package edu.com.wjt219971332.service.impl;

import edu.com.wjt219971332.entity.Singer;
import edu.com.wjt219971332.dao.SingerDao;
import edu.com.wjt219971332.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;


@Service
public class SingerServiceImpl implements SingerService {
    @Autowired
    private SingerDao singerDao;

    @Override
    public Singer queryById(Integer singerid) {
        return this.singerDao.queryById(singerid);
    }

    @Override
    public Page<Singer> queryByPage(Singer singer, PageRequest pageRequest) {
        long total = this.singerDao.count(singer);
        return new PageImpl<>(this.singerDao.queryAllByLimit(singer, pageRequest), pageRequest, total);
    }


    @Override
    public int insert(Singer singer) {
        return this.singerDao.insert(singer);
    }

    @Override
    public int update(Singer singer) {
        return this.singerDao.update(singer);
    }

    @Override
    public boolean deleteById(Integer singerid) {
        return this.singerDao.deleteById(singerid) > 0;
    }

    @Override
    public List<Singer> queryByusername(String name) {
        return singerDao.queryByusername(name);
    }

    @Override
    public Singer queryBysingername(String asinger) {
        return this.singerDao.queryBysingername(asinger);
    }
}
